package com.MedDroid.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
import com.MedDroid.MainApp;
import com.MedDroid.R;
import com.MedDroid.task.LoadUserListTask;

import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: Romen
 * Date: 02/12/13
 * Time: 5:31 PM
 * Description:
 */
public class UserListActivity extends Activity
{
	public Button BtnFindUser;
	public ListView ListUser;
	public ArrayList<String> ListNames = new ArrayList<String>();//ArrayList of strings holding the users names
	public ArrayList<Integer> ListUserId = new ArrayList<Integer>();//ArrayList of user id Integers
	private int SelectedId;

	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.user_list);

		ListUser = (ListView) findViewById(R.id.listUser);
	}

	@Override
	public void onResume()
	{
		super.onResume();
		new LoadUserListTask(((MainApp)getApplication()).getAuthentication(), ((MainApp)getApplication()).getDatabase(), UserListActivity.this).execute();
	}

	@Override
	protected void onStop()
	{
		super.onStop();
		((MainApp)getApplication()).onStop();
	}

	public void makeList()
	{
		MainApp.log("Making List.");
		MainApp.log(Integer.toString(ListNames.size()));
		ArrayAdapter<String> adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1, ListNames);
		ListUser.setAdapter(adapter);
		ListUser.setOnItemClickListener(new AdapterView.OnItemClickListener()
		{
			@Override
			public void onItemClick(AdapterView<?> adapterView, View view, int i, long l)
			{
				Intent intent = new Intent(UserListActivity.this, ViewProfileActivity.class);
				intent.putExtra("UserID", ListUserId.get(i));
				startActivity(intent);
			}
		});
	}
}